﻿<!--
// ****************************************************************************
// <author>mishkin Ivan</author>
// <email>Mishkin_Ivan@mail.ru</email>
// <date>28.01.2015</date>
// <project>ItemsFilter</project>
// <license> GNU General Public License version 3 (GPLv3) </license>
// ****************************************************************************
-->
<UserControl x:Class="Northwind.NET.Sample.View.CustomersView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:EF6Model="clr-namespace:Northwind.NET.EF6Model;assembly=Northwind.NET.EF6Model"
             xmlns:bsFilter="http://schemas.bolapansoft.com/xaml/Controls/ItemsFilter"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:local="clr-namespace:Northwind.NET.Sample"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:vm="clr-namespace:Northwind.NET.Sample.ViewModel"
             xmlns:vw="clr-namespace:Northwind.NET.Sample.View"
             x:Name="UserControl"
             DataContext="{Binding Path=CustomersTreeList,
                                   Source={StaticResource Workspace}}"
             d:DesignHeight="591.192"
             d:DesignWidth="866.126"
             mc:Ignorable="d">
    <UserControl.Resources>
        <vw:ObjectToCustomerConverter x:Key="ObjectToCustomerConverter" />
        <SolidColorBrush x:Key="ListBorder" Color="#828790" />
        <Style TargetType="{x:Type bsFilter:StringFilterView}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type bsFilter:StringFilterView}">
                        <Border Height="Auto"
                                Margin="{TemplateBinding Margin}"
                                HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                                VerticalAlignment="{TemplateBinding VerticalAlignment}"
                                BorderBrush="#FF999FD3"
                                BorderThickness="1"
                                CornerRadius="3"
                                Padding="1">
                            <Grid>
                                <Grid.Background>
                                    <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                                        <GradientStop Offset="0" Color="#FFB0B4D6" />
                                        <GradientStop Offset="0.3" Color="White" />
                                        <GradientStop Offset="0.993" Color="#FFB4B8D8" />
                                        <GradientStop Offset="0.74" Color="#FFF8F9FB" />
                                    </LinearGradientBrush>
                                </Grid.Background>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>

                                <TextBlock Margin="1"
                                           HorizontalAlignment="Right"
                                           VerticalAlignment="Center"
                                           FontFamily="/Northwind.NET.Sample;component/Fonts/#Vijaya"
                                           FontSize="18"
                                           Text="Country:"
                                           TextWrapping="Wrap" />

                                <TextBox x:Name="PART_Input"
                                         Grid.Column="1"
                                         Margin="1"
                                         VerticalAlignment="Center"
                                         FontFamily="/Northwind.NET.Sample;component/Fonts/#Vijaya"
                                         FontSize="18"
                                         Padding="1,1,1,1"
                                         Text="{Binding Model.Value,
                                                        Mode=TwoWay,
                                                        UpdateSourceTrigger=PropertyChanged,
                                                        RelativeSource={RelativeSource TemplatedParent}}"
                                         TextWrapping="NoWrap" />
                                <Button Grid.Column="2" Style="{DynamicResource FilterClearButtonStyle}" />
                            </Grid>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style TargetType="{x:Type TreeViewItem}">
            <Setter Property="IsExpanded" Value="True" />
        </Style>
        <Style x:Key="TreeViewStyle" TargetType="{x:Type TreeView}">
            <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" />
            <Setter Property="BorderBrush" Value="{StaticResource ListBorder}" />
            <Setter Property="BorderThickness" Value="1" />
            <Setter Property="Padding" Value="1" />
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
            <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
            <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
            <Setter Property="VerticalContentAlignment" Value="Center" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TreeView}">
                        <Border x:Name="Bd"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                SnapsToDevicePixels="true">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="*" />
                                </Grid.RowDefinitions>
                                <Path Margin="3"
                                      HorizontalAlignment="Left"
                                      Data="M 0,9 h6 v-6 z"
                                      Fill="#FFCCCCCD" />
                                <bsFilter:FilterControl Key="Country"
                                                        Grid.Row="1"
                                                        Grid.Column="1"
                                                        Margin="3"
                                                        ParentCollection="{TemplateBinding ItemsSource}">
                                    <bsFilter:FilterControl.FilterInitializersManager>
                                        <bsFilter:FilterInitializersManager>
                                            <vm:CustomersTreeFilterInitializer />
                                        </bsFilter:FilterInitializersManager>
                                    </bsFilter:FilterControl.FilterInitializersManager>
                                </bsFilter:FilterControl>
                                <StackPanel Grid.Column="1" Orientation="Horizontal">
                                    <TextBlock Margin="3,0"
                                               FontFamily="Times New Roman"
                                               FontSize="14.667"
                                               FontWeight="Bold"
                                               Text="Northwind customers (" />
                                    <TextBlock Margin="3,0"
                                               FontFamily="Times New Roman"
                                               FontSize="14.667"
                                               FontWeight="Bold"
                                               Text="{Binding Count}" />
                                    <TextBlock Margin="3,0"
                                               FontFamily="Times New Roman"
                                               FontSize="14.667"
                                               FontWeight="Bold"
                                               Text=")" />
                                </StackPanel>
                                <ScrollViewer x:Name="_tv_scrollviewer_"
                                              Grid.Row="2"
                                              Grid.ColumnSpan="2"
                                              CanContentScroll="false"
                                              Focusable="false"
                                              HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
                                              Padding="{TemplateBinding Padding}"
                                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                              VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}">
                                    <ItemsPresenter />
                                </ScrollViewer>
                            </Grid>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter TargetName="Bd" Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
                            </Trigger>
                            <Trigger Property="VirtualizingStackPanel.IsVirtualizing" Value="true">
                                <Setter TargetName="_tv_scrollviewer_" Property="CanContentScroll" Value="true" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="VirtualizingStackPanel.IsVirtualizing" Value="true">
                    <Setter Property="ItemsPanel">
                        <Setter.Value>
                            <ItemsPanelTemplate>
                                <VirtualizingStackPanel />
                            </ItemsPanelTemplate>
                        </Setter.Value>
                    </Setter>
                </Trigger>
            </Style.Triggers>
        </Style>
        <DataTemplate x:Key="TreeCustomersItemTemplate">
            <StackPanel>
                <TextBlock Text="{Binding Count}" />
                <TextBlock Text="{Binding Country}" />
            </StackPanel>
        </DataTemplate>
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="1.2*" MinWidth="150" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>


        <TreeView x:Name="listCustomersTreeView"
                  Grid.Row="0"
                  Grid.Column="0"
                  MinWidth="150"
                  MinHeight="100"
                  Margin="5"
                  ItemsSource="{Binding}"
                  Style="{DynamicResource TreeViewStyle}">


            <TreeView.ItemTemplate>
                <HierarchicalDataTemplate ItemsSource="{Binding Cities}">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Margin="3,0"
                                   FontStyle="Italic"
                                   Text="{Binding Country}" />
                        <TextBlock Margin="3,0"
                                   FontStyle="Italic"
                                   Text="(cities: " />
                        <TextBlock Margin="3,0"
                                   FontStyle="Italic"
                                   Text="{Binding Items.Count,
                                                  Mode=OneWay,
                                                  RelativeSource={RelativeSource FindAncestor,
                                                                                 AncestorType={x:Type TreeViewItem}}}" />
                        <TextBlock Margin="3,0"
                                   FontStyle="Italic"
                                   Text=")" />
                    </StackPanel>
                    <HierarchicalDataTemplate.ItemTemplate>
                        <HierarchicalDataTemplate ItemsSource="{Binding Customers}">
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Margin="3,0" Text="{Binding City}" />
                                <TextBlock Margin="3,0" Text="(customers: " />
                                <TextBlock Margin="3,0" Text="{Binding Items.Count, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TreeViewItem}}}" />
                                <TextBlock Margin="3,0" Text=")" />
                            </StackPanel>
                            <HierarchicalDataTemplate.ItemTemplate>
                                <DataTemplate>
                                    <Border Margin="3"
                                            BorderBrush="#FFEAE2B1"
                                            BorderThickness="1"
                                            CornerRadius="3"
                                            Padding="5"
                                            d:DesignHeight="31.42"
                                            d:DesignWidth="64.25">
                                        <StackPanel Orientation="Vertical">
                                            <TextBlock HorizontalAlignment="Center"
                                                       FontFamily="Times New Roman"
                                                       FontSize="13.333"
                                                       FontWeight="Bold"
                                                       Text="{Binding Name}" />
                                            <StackPanel Orientation="Horizontal">
                                                <TextBlock Margin="3" Text="{Binding ContactTitle}" />
                                                <TextBlock Margin="3"
                                                           FontWeight="Bold"
                                                           Text="{Binding ContactName}" />
                                            </StackPanel>
                                        </StackPanel>
                                    </Border>
                                </DataTemplate>
                            </HierarchicalDataTemplate.ItemTemplate>
                        </HierarchicalDataTemplate>
                    </HierarchicalDataTemplate.ItemTemplate>
                </HierarchicalDataTemplate>
            </TreeView.ItemTemplate>

        </TreeView>
        <GridSplitter Width="5"
                      Margin="0,5,-3,5"
                      HorizontalAlignment="Right" />
        <Border Grid.Column="1"
                Margin="5"
                Background="#FFD4D4D4"
                BorderBrush="#FF828790"
                BorderThickness="1"
                Padding="5">


            <Grid x:Name="grid1"
                  DataContext="{Binding SelectedItem,
                                        Converter={StaticResource ObjectToCustomerConverter},
                                        ElementName=listCustomersTreeView}"
                  d:DataContext="{d:DesignData Source=../SampleData/Customer.xaml}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <TextBlock Grid.ColumnSpan="2"
                           Margin="25,5,25,5"
                           FontFamily="Times New Roman"
                           FontSize="26.667"
                           FontWeight="Bold"
                           Foreground="{DynamicResource {x:Static SystemColors.HotTrackBrushKey}}"
                           Text="Customer details" />
                <Label Grid.Row="5"
                       Grid.Column="0"
                       Margin="3,4,0,3"
                       HorizontalAlignment="Left"
                       VerticalAlignment="Center"
                       Content="Address:" />
                <TextBox x:Name="addressTextBox"
                         Grid.Row="5"
                         Grid.Column="1"
                         Height="Auto"
                         MinHeight="24"
                         Margin="3,4,0,5"
                         VerticalAlignment="Center"
                         Text="{Binding Address,
                                        Mode=TwoWay,
                                        NotifyOnValidationError=true,
                                        ValidatesOnExceptions=true}" />
            
                <TextBox Grid.Row="4"
                         Grid.Column="1"
                         Width="120"
                         Height="24"
                         MinWidth="250"
                         Margin="3,5,0,6"
                         HorizontalAlignment="Left"
                         VerticalAlignment="Center"
                         IsReadOnly="False"
                         Text="{Binding City}" />
                <Label Grid.Row="3"
                       Grid.Column="0"
                       Margin="3,4,0,5"
                       HorizontalAlignment="Left"
                       VerticalAlignment="Center"
                       Content="Country:" />
                <!--
                    <ComboBox x:Name="countryComboBox"
                    Grid.Row="2"
                    Grid.Column="1"
                    Height="Auto"
                    MinWidth="250"
                    Margin="3,5,0,5"
                    HorizontalAlignment="Left"
                    VerticalAlignment="Center"
                    IsEditable="True"
                    IsReadOnly="False"
                    SelectedValue="{Binding Country}">
                    <ComboBox.ItemsPanel>
                    <ItemsPanelTemplate>
                    <VirtualizingStackPanel />
                    </ItemsPanelTemplate>
                    </ComboBox.ItemsPanel>
                    </ComboBox>
                -->
                <TextBox Grid.Row="3"
                         Grid.Column="1"
                         Height="24"
                         MinWidth="250"
                         Margin="3,6,0,5"
                         HorizontalAlignment="Left"
                         VerticalAlignment="Center"
                         IsReadOnly="False"
                         Text="{Binding Country}" />
                <Label Grid.Row="1"
                       Grid.Column="0"
                       Margin="3,4,0,3"
                       HorizontalAlignment="Left"
                       VerticalAlignment="Center"
                       Content="Name:" />
                <TextBox x:Name="nameTextBox"
                         Grid.Row="1"
                         Grid.Column="1"
                         Height="24"
                         MinWidth="150"
                         Margin="3,4,0,5"
                         VerticalAlignment="Center"
                         Text="{Binding Name,
                                        Mode=TwoWay,
                                        NotifyOnValidationError=true,
                                        ValidatesOnExceptions=true}" />
                <Label Grid.Row="2"
                       Grid.Column="0"
                       Margin="3,3,0,4"
                       HorizontalAlignment="Left"
                       VerticalAlignment="Center"
                       Content="Region:" />
                <TextBox x:Name="regionTextBox"
                         Grid.Row="2"
                         Grid.Column="1"
                         Height="24"
                         MinWidth="150"
                         Margin="3,5,0,4"
                         HorizontalAlignment="Left"
                         VerticalAlignment="Center"
                         Text="{Binding Region,
                                        Mode=TwoWay,
                                        NotifyOnValidationError=true,
                                        ValidatesOnExceptions=true}" />
                <Label Grid.Row="4"
                       Grid.Column="0"
                       Margin="3,5,0,4"
                       HorizontalAlignment="Left"
                       VerticalAlignment="Center"
                       Content="City:" />
                <Label Grid.Row="6"
                       Grid.Column="0"
                       Margin="3,3,0,4"
                       HorizontalAlignment="Left"
                       VerticalAlignment="Center"
                       Content="Code:" />
                <TextBox x:Name="codeTextBox"
                         Grid.Row="6"
                         Grid.Column="1"
                         Width="120"
                         Height="24"
                         Margin="3,5,0,4"
                         HorizontalAlignment="Left"
                         VerticalAlignment="Center"
                         Text="{Binding Code,
                                        Mode=TwoWay,
                                        NotifyOnValidationError=true,
                                        ValidatesOnExceptions=true}" />
                <Label Grid.Row="8"
                       Grid.Column="0"
                       Margin="3,3,0,4"
                       HorizontalAlignment="Left"
                       VerticalAlignment="Center"
                       Content="Contact Name:" />
                <TextBox x:Name="contactNameTextBox"
                         Grid.Row="8"
                         Grid.Column="1"
                         Height="24"
                         MinWidth="150"
                         Margin="3,5,0,4"
                         HorizontalAlignment="Left"
                         VerticalAlignment="Center"
                         Text="{Binding ContactName,
                                        Mode=TwoWay,
                                        NotifyOnValidationError=true,
                                        ValidatesOnExceptions=true}" />
                <Label Grid.Row="7"
                       Grid.Column="0"
                       Margin="3,4,0,3"
                       HorizontalAlignment="Left"
                       VerticalAlignment="Center"
                       Content="Contact Title:" />
                <TextBox x:Name="contactTitleTextBox"
                         Grid.Row="7"
                         Grid.Column="1"
                         Height="24"
                         MinWidth="150"
                         Margin="3,4,0,5"
                         HorizontalAlignment="Left"
                         VerticalAlignment="Center"
                         Text="{Binding ContactTitle,
                                        Mode=TwoWay,
                                        NotifyOnValidationError=true,
                                        ValidatesOnExceptions=true}" />
                <Label Grid.Row="9"
                       Grid.Column="0"
                       Margin="3,4,0,3"
                       HorizontalAlignment="Left"
                       VerticalAlignment="Center"
                       Content="Fax:" />
                <TextBox x:Name="faxTextBox"
                         Grid.Row="9"
                         Grid.Column="1"
                         Height="24"
                         MinWidth="120"
                         Margin="3,4,0,5"
                         HorizontalAlignment="Left"
                         VerticalAlignment="Center"
                         Text="{Binding Fax,
                                        Mode=TwoWay,
                                        NotifyOnValidationError=true,
                                        ValidatesOnExceptions=true}" />
                <Label Grid.Row="10"
                       Grid.Column="0"
                       Margin="3,3,0,4"
                       HorizontalAlignment="Left"
                       VerticalAlignment="Center"
                       Content="ID:" />
                <TextBox x:Name="iDTextBox"
                         Grid.Row="10"
                         Grid.Column="1"
                         Height="24"
                         MinWidth="120"
                         Margin="3,5,0,4"
                         HorizontalAlignment="Left"
                         VerticalAlignment="Center"
                         Text="{Binding ID,
                                        Mode=TwoWay,
                                        NotifyOnValidationError=true,
                                        ValidatesOnExceptions=true}" />
                <Label Grid.Row="11"
                       Grid.Column="0"
                       Margin="3,4,0,4"
                       HorizontalAlignment="Left"
                       VerticalAlignment="Center"
                       Content="Phone:" />
                <TextBox x:Name="phoneTextBox"
                         Grid.Row="11"
                         Grid.Column="1"
                         Height="24"
                         MinWidth="120"
                         Margin="3,5,0,5"
                         HorizontalAlignment="Left"
                         VerticalAlignment="Center"
                         Text="{Binding Phone,
                                        Mode=TwoWay,
                                        NotifyOnValidationError=true,
                                        ValidatesOnExceptions=true}" />
                <Label Grid.Row="12"
                       Grid.Column="0"
                       Margin="3,4,0,3"
                       HorizontalAlignment="Left"
                       VerticalAlignment="Center"
                       Content="Postal Code:" />
                <TextBox x:Name="postalCodeTextBox"
                         Grid.Row="12"
                         Grid.Column="1"
                         Height="24"
                         MinWidth="120"
                         Margin="3,4,0,5"
                         HorizontalAlignment="Left"
                         VerticalAlignment="Center"
                         Text="{Binding PostalCode,
                                        Mode=TwoWay,
                                        NotifyOnValidationError=true,
                                        ValidatesOnExceptions=true}" />

            </Grid>


        </Border>


    </Grid>
</UserControl>